package com.example.yyy

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Build
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import org.jetbrains.anko.intentFor


class SendRemoteNotify(private val context: Context, private val title: String, private val message: String){
    init {

        //声明一个点击通知消息时触发的动作意图
        val clickIntent = context.intentFor<MainActivity>()
        val intent = PendingIntent.getActivity(
            context,
            R.string.app_name,
            clickIntent,
            PendingIntent.FLAG_CANCEL_CURRENT
        )
        //构建消息参数
        val builder: NotificationCompat.Builder = NotificationCompat.Builder(context, "CHANNELID")
        builder.setContentIntent(intent)
            .setAutoCancel(true)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setSubText("这是副本22")
            .setTicker("简单消息")
            .setWhen(System.currentTimeMillis())
            .setContent(getRemotes())
        //获取通知管理器
        val manager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channel = NotificationChannel("6", "channel6", NotificationManager.IMPORTANCE_DEFAULT)
            channel.enableLights(true)
            channel.lightColor = Color.green(1)
            channel.setShowBadge(true)
            manager.createNotificationChannel(channel)
            builder.setChannelId("6")
        }
        val n = builder.build()
        manager.notify(1, n)
    }
    private fun getRemotes():RemoteViews{
        val remoteViews = RemoteViews(context.packageName, R.layout.notif)
        remoteViews.setProgressBar(R.id.pb_rm_count,100,60,false)
        return remoteViews
    }
}